package com.sos.controller;

import com.sos.model.dto.HelperInfoDTO;
import com.sos.model.dto.HelperInfoUpdateDTO;
import com.sos.model.entity.HelperInfo;
import com.sos.model.vo.ResultVO;
import com.sos.service.HelperInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/helper-info")
@RequiredArgsConstructor
@Tag(name = "帮助内容信息管理", description = "帮助者信息的增改查接口")
@SecurityRequirement(name = "bearerAuth")
public class HelperInfoController {

    private final HelperInfoService helperInfoService;

    /**
     * 添加帮助者信息
     */
    @PostMapping
    @Operation(summary = "添加帮助者信息", description = "添加当前用户的帮助者信息")
    public ResultVO<HelperInfo> addHelperInfo(@Valid @RequestBody HelperInfoDTO helperInfoDTO) {
        return helperInfoService.addHelperInfo(helperInfoDTO);
    }

    /**
     * 更新帮助者信息
     */
    @PutMapping("/{helperInfoId}")
    @Operation(summary = "更新帮助者信息", description = "更新当前用户的帮助者信息")
    public ResultVO<HelperInfo> updateHelperInfo(
            @PathVariable Long helperInfoId,
            @Valid @RequestBody HelperInfoUpdateDTO updateDTO) {
        return helperInfoService.updateHelperInfo(helperInfoId, updateDTO);
    }

    /**
     * 更新当前用户帮助者信息（无需传入ID）
     */
    @PutMapping("/me")
    @Operation(summary = "更新当前用户帮助者信息", description = "更新当前用户自己的帮助者信息，无需传入ID")
    public ResultVO<HelperInfo> updateCurrentHelperInfo(@Valid @RequestBody HelperInfoUpdateDTO updateDTO) {
        return helperInfoService.updateCurrentHelperInfo(updateDTO);
    }

    /**
     * 获取当前用户帮助者信息
     */
    @GetMapping
    @Operation(summary = "获取当前用户帮助者信息", description = "获取当前用户的帮助者信息")
    public ResultVO<HelperInfo> getHelperInfo() {
        return helperInfoService.getHelperInfo();
    }

    /**
     * 根据ID获取帮助者信息
     */
    @GetMapping("/{id}")
    @Operation(summary = "根据ID获取帮助者信息", description = "根据ID获取帮助者信息")
    public ResultVO<HelperInfo> getHelperInfoById(@PathVariable Long id) {
        return helperInfoService.getHelperInfoById(id);
    }
}